package demo1;

public class Stu implements Comparable<Stu>{
    //使用Comparable 方法之后要重写compareto 方法 此时对于类的入侵性表较强
    //后续如果要修改逻辑比较麻烦 需要涉及到逻辑代码的修改
    private String name;
    private int age;

    public Stu(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Stu{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


    @Override
    public int compareTo(Stu o) {
        return this.age - o.age;
    }
}
